﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DiaosFix.Core
{
    public class UserTypeOperator
    {
        public Response<List<Users>> FindUsersInRole(PubConstant.UserTypes userType)
        {
            var response = new Response<List<Users>>();
            string strUserType = userType.ToString();

            try
            {
                using (DiaosFixEntities context = new DiaosFixEntities())
                {
                    var q = context.UserType.Where(p => p.Name == strUserType).SingleOrDefault();
                    if (null != q)
                    {
                        response.IsSuccess = true;
                        response.Message = string.Empty;
                        response.Item = q.Users.ToList();
                    }
                    else
                    {
                        response.IsSuccess = false;
                        response.Message = "Cannot find usertype " + strUserType;
                        response.Item = null;
                    }
                }
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                response.Message = "Shit happens, " + ex.Message;
                response.Item = null;
            }
            return response;
        }
    }
}
